<template>
  <div>
    <Comheadernav></Comheadernav>
    <Comheader></Comheader>
    <div class="container">
      <div class="sub-header">
        <div class="bread container" v-if="subList">
          <div class="bread-item">
            <a href="#/" class="router-link-active">首页</a>
          </div>
          <i class="iconfont icon-angle-right"></i>
          <div class="bread-item">
            <span>{{ subList.parentName }}</span>

            <i class="iconfont icon-angle-right"></i>

            <span>{{ subList.name }}</span>
          </div>
        </div>
      </div>

      <div class="sub-filter">
        <div class="item">
          <div class="head">品牌：</div>
          <div class="con">
            <a href="javascript" class="lv">全部</a
            ><a href="JavaScript:;">{{ subList.brands[0].name }}</a>
          </div>
        </div>
        <div class="item" v-for="item in subList.saleProperties">
          <div class="head">{{ item.name }}:</div>
          <div class="con">
            <a href="javascript" class="lv">全部</a
            ><a href="JavaScript:;" v-for="i in item.properties">{{
              i.name
            }}</a>
          </div>
        </div>
      </div>

      <div class="goods-list">
        <div class="title">
          <div class="sub-sortzx">
            <div class="sortzx">
            <a href="javascript:;">默认排序</a>
            <a href="javascript:;">最新商品</a>
            <a href="javascript:;">最高人气</a>
            <a href="javascript:;">评论最多</a>
            <a href="javascript:;">价格排序</a>
            </div>
            <div class="checkzx">
            <div class="xtx-checkbox">
            <input type="checkbox">
            <span>仅显示有货商品</span>
            </div>
            <div class="xtx-checkbox">
            <input type="checkbox">
            <span>仅显示特惠商品</span>
            </div>
            </div>
            </div>
        </div>
        <ul>
          <li v-for="goods in sort">
            <a href="javascript:;">
              <img :src="goods.picture" alt="" />
              <h3>{{ goods.name }}</h3>
              <p>{{ goods.desc }}</p>
              <span>{{ goods.price }}</span>
            </a>
          </li>
        </ul>
      </div>
    </div>

    <Comfooter></Comfooter>
  </div>
</template>

<script>
import Comheader from "@/erabbit/layout/header.vue";
import Comheadernav from "@/erabbit/layout/nav.vue";
import Comfooter from "@/erabbit/foooterNav.vue";
import axios from "axios";
export default {
  components: {
    Comheader,
    Comheadernav,
    Comfooter,
  },
  data() {
    return {
      subList: [],
      sort: [],
    };
  },
  methods: {
    getCategory() {
      this.axios(
        `http://pcapi-xiaotuxian-front-devtest.itheima.net/category/sub/filter?id=${this.$route.params.id}`
      ).then((res) => {
        if (res.data.msg == "操作成功") {
          this.subList = res.data.result;
          console.log(this.subList);
        }
      }),
        axios({
          url: "http://pcapi-xiaotuxian-front-devtest.itheima.net/category/goods/temporary",
          method: "post",
          data: {
            account: this.userVal,
            password: this.passVal,
          },
        }).then((res) => {
          console.log(res.data.result);
          this.sort = res.data.result.items;
          console.log(this.sort);
        });
    },
  },
  mounted() {
    this.getCategory();
  },
  watch: {
    $route: "getCategory",
  },
  //当前路由的子路由或者参数变化时触发
  beforeRouteUpdate(to, from, next) {
    console.log(to, from);
    next();
  },
};
</script>

<style lang="scss" scoped>
.title{
  padding: 0 20px ;
}
.sub-filter {
  background-color: #fff;
  padding: 25px;
}
.item {
  display: flex;
  width: 100%;

  .head {
    width: 80px;
  }
  a {
    margin-right: 36px;
    transition: all 0.3s;
    display: inline-block;
    max-width: 112px;
    line-height: 40px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
  .lv {
    color: #27ba9b;
  }
  .con {
    flex: 1;
  }
}
.goods-list {
  margin-top: 20px;
  background-color: #fff;
  ul {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    padding: 0 5px;
    li {
      margin-right: 20px;
      margin-bottom: 20px;
      a {
        display: block;
        width: 220px;
        padding: 20px 30px;
        text-align: center;
        transition: all 0.5s;
        text-decoration: none;
        color: #333;
        outline: none;
      }
    }
    h3,
    p,
    span {
      padding-top: 10px;
    }
    h3 {
      font-weight: normal;
      font-size: 16px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    p {
      color: #999;
      height: 29px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
      font-size: 14px;
    }
    span {
      color: #cf4444;
      font-size: 20px;
      margin-top: 10px;
    }
    img {
      width: 160px;
      height: 160px;
    }
  }
}
.goods-listzx {
  background: #fff;
  padding: 0 25px;
  margin-top: 25px;
}

.sub-sortzx {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sortzx {
  display: flex;
}

.sortzx a:nth-child(1) {
  background: #27ba9b;
  border-color: #27ba9b;
  color: #fff;
}

.sortzx a {
  height: 30px;
  line-height: 28px;
  border: 1px solid #e4e4e4;
  padding: 0 20px;
  margin-right: 20px;
  color: #999;
  border-radius: 2px;
  position: relative;
  transition: all 0.3s;
}

.xtx-checkbox {
  margin-left: 20px;
  color: #999;
  display: inline-block;
  margin-right: 2px;
}

.xtx-checkbox input {
  vertical-align: middle;
}

.xtx-checkbox span {
  margin-left: 2px;
}
</style>